from models.entity.module import Module
from models.entity.button import Button
from models.entity.role import RoleWithButton
import uuid

modules=Module.query.all()
print(1111,modules)
for item in modules:
    if Button.query.filter(Button.module_id == item.id).filter(Button.name == ".").first() is None:
        newButton = Button()
        newButton.parent_id = 0
        newButton.module_id = item.id
        newButton.code = uuid.uuid4().hex
        newButton.name = "."
        if newButton.save() is False:
            print("New button build error")
            exit()
print("DONE")

buttons=Button.query.all()
for item in buttons:
    newConnector=RoleWithButton()
    newConnector.role_id = 2
    newConnector.button_id = item.id
    if newConnector.save()!=0:
        print("New connector build error")
        exit()
print("DONE")
